package com.linksfield.topup.service.impl;

import com.alibaba.fastjson.JSON;
import com.linksfield.topup.config.dto.PageAndSort;
import com.linksfield.topup.config.dto.ResultDataDto;
import com.linksfield.topup.config.dto.StringOutputConstant;
import com.linksfield.topup.entity.common.*;
import com.linksfield.topup.entity.interfaces.comlinkmanage.create.first.request.FirstPlanLangTextConfig;
import com.linksfield.topup.entity.interfaces.comlinkmanage.create.first.request.RequestFirstPlanCreate;
import com.linksfield.topup.entity.interfaces.comlinkmanage.create.fourth.request.FourthPlanLangTextConfig;
import com.linksfield.topup.entity.interfaces.comlinkmanage.create.fourth.request.FourthPlanPayTextConfig;
import com.linksfield.topup.entity.interfaces.comlinkmanage.create.fourth.request.RequestFourthPlanCreate;
import com.linksfield.topup.entity.interfaces.comlinkmanage.create.second.request.RequestSecondPlanCreate;
import com.linksfield.topup.entity.interfaces.comlinkmanage.create.second.request.SecondPlanLangTextConfig;
import com.linksfield.topup.entity.interfaces.comlinkmanage.create.third.request.RequestThirdPlanCreate;
import com.linksfield.topup.entity.interfaces.comlinkmanage.create.third.request.ThirdPlanLangTextConfig;
import com.linksfield.topup.entity.interfaces.comlinkmanage.edit.context.first.request.RequestFirstContentEdit;
import com.linksfield.topup.entity.interfaces.comlinkmanage.edit.context.fourth.request.FourthPlanPayEdit;
import com.linksfield.topup.entity.interfaces.comlinkmanage.edit.context.fourth.request.RequestFourthPayEdit;
import com.linksfield.topup.entity.interfaces.comlinkmanage.edit.context.second.request.RequestSecondContentEdit;
import com.linksfield.topup.entity.interfaces.comlinkmanage.edit.context.third.request.RequestThirdContentEdit;
import com.linksfield.topup.entity.interfaces.comlinkmanage.edit.langtext.first.request.FirstPlanLangEdit;
import com.linksfield.topup.entity.interfaces.comlinkmanage.edit.langtext.first.request.RequestFirstLangEdit;
import com.linksfield.topup.entity.interfaces.comlinkmanage.edit.langtext.fourth.request.FourthPlanLangEdit;
import com.linksfield.topup.entity.interfaces.comlinkmanage.edit.langtext.fourth.request.RequestFourthLangEdit;
import com.linksfield.topup.entity.interfaces.comlinkmanage.edit.langtext.second.request.RequestSecondLangEdit;
import com.linksfield.topup.entity.interfaces.comlinkmanage.edit.langtext.second.request.SecondPlanLangEdit;
import com.linksfield.topup.entity.interfaces.comlinkmanage.edit.langtext.third.request.RequestThirdLangEdit;
import com.linksfield.topup.entity.interfaces.comlinkmanage.edit.langtext.third.request.ThirdPlanLangEdit;
import com.linksfield.topup.entity.interfaces.comlinkmanage.langlist.request.RequestLangList;
import com.linksfield.topup.entity.interfaces.comlinkmanage.langlist.response.ResponseLangList;
import com.linksfield.topup.entity.interfaces.comlinkmanage.operation.request.RequestPlanOperation;
import com.linksfield.topup.entity.interfaces.comlinkmanage.search.request.RequestContentPlanSearch;
import com.linksfield.topup.entity.interfaces.comlinkmanage.search.response.ResponseContentPlanSearch;
import com.linksfield.topup.entity.interfaces.comlinkmanage.view.request.RequestContentPlanView;
import com.linksfield.topup.entity.interfaces.comlinkmanage.view.response.first.FirstPlanLangConfig;
import com.linksfield.topup.entity.interfaces.comlinkmanage.view.response.first.ResponseFirstPlanView;
import com.linksfield.topup.entity.interfaces.comlinkmanage.view.response.fourth.FourthPlanLangConfig;
import com.linksfield.topup.entity.interfaces.comlinkmanage.view.response.fourth.FourthPlanPayConfig;
import com.linksfield.topup.entity.interfaces.comlinkmanage.view.response.fourth.ResponseFourthPlanView;
import com.linksfield.topup.entity.interfaces.comlinkmanage.view.response.second.ResponseSecondPlanView;
import com.linksfield.topup.entity.interfaces.comlinkmanage.view.response.second.SecondPlanLangConfig;
import com.linksfield.topup.entity.interfaces.comlinkmanage.view.response.third.ResponseThirdPlanView;
import com.linksfield.topup.entity.interfaces.comlinkmanage.view.response.third.ThirdPlanLangConfig;
import com.linksfield.topup.mapper.PartnerConfigMapper;
import com.linksfield.topup.service.PartnerConfigService;
import com.linksfield.topup.service.SequenceService;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@Service("configService")
@Transactional(rollbackFor = Exception.class)

/**
 * 企业内容配置业务逻辑处理实现类
 *
 * @author: lm
 * @date: 2019-12-09 15:40
 */

public class PartnerConfigServiceImpl implements PartnerConfigService {

    private static Logger logger = Logger.getLogger(PartnerConfigServiceImpl.class);

    @Resource
    PartnerConfigMapper configMapper;

    @Autowired
    CommonUtilsServiceImpl utilsService;

    @Autowired
    SequenceService sequenceService;

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


    /***
     * 根据条件分页查询企业的H5内容服务方案
     * @param request
     * @param token
     * @return
     */
    @Override
    public ResultDataDto contentPlanSearch(RequestContentPlanSearch request, String token) {

        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        //1,先去公共服务类验证token
        String results = utilsService.checkAdmin(token);

        if (StringUtils.isBlank(results) || !StringOutputConstant.CODE_SUCCESS.equals(results)) {
            // 验证token出现问题，直接返回
            return ResultDataDto.addOperationFailure(results);
        }
        //确认安全，开始验证参数
        if (StringUtils.isBlank(request.getTradeType()) || StringUtils.isBlank(request.getLang()) || StringUtils.isBlank(request.getVersion()) ||
                null == request.getCondition() || null == request.getRp() || null == request.getCurrentPage()) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_ERROR);
        }

        //1,先去把分页信息拿回来
        long rowCount = configMapper.searchPageCount(request);
        //如果前端未指定查询页码和显示多少行
        Integer rp;
        if (null != request.getRp()) {
            rp = request.getRp();
        } else {
            rp = 10;
        }

        Integer currentPage;
        if (null != request.getCurrentPage()) {
            currentPage = request.getCurrentPage();
        } else {
            currentPage = 1;
        }

        //计算出来的分页的数据
        PageAndSort pageHelper = new PageAndSort();
        pageHelper.setPage(currentPage);
        pageHelper.setRp(rp);
        pageHelper.setRowCount(rowCount);

        //2,拿着分页信息去数据库查询具体的用户数据列表记录
        List<PartnerConfigContent> contentList = configMapper.contentPlanSearch(request, pageHelper);

        List<ResponseContentPlanSearch> responseList = new ArrayList<ResponseContentPlanSearch>();
        ResponseContentPlanSearch response = null;

        for (PartnerConfigContent c : contentList) {

            response = new ResponseContentPlanSearch();
            response.setPlanCode(c.getPlanCode());
            response.setPartnerCode(c.getPartnerCode());
            response.setPartnerName(c.getPartnerName());
            try {
                response.setCreateDate(sdf.format(s.parse(s.format(c.getCreateDate()))));
                response.setUpdateDate(sdf.format(s.parse(s.format(c.getUpdateDate()))));
            } catch (Exception e) {
                logger.debug("时间转换发生了异常！" + e);
            }
            response.setConfigType(c.getConfigType());
            if (c.getConfigType().equals("1")) {
                response.setConfigTypeShow("流量查询");
            } else if (c.getConfigType().equals("2")) {
                response.setConfigTypeShow("联系供应商");
            } else if (c.getConfigType().equals("3")) {
                response.setConfigTypeShow("直接跳转");
            } else if (c.getConfigType().equals("4")) {
                response.setConfigTypeShow("订购");
            }

            response.setConfigStatus(c.getConfigStatus());
            if (c.getConfigStatus().equals("1")) {
                response.setConfigStatusShow("未启用");
            } else if (c.getConfigStatus().equals("2")) {
                response.setConfigStatusShow("已启用");
            } else if (c.getConfigStatus().equals("3")) {
                response.setConfigStatusShow("已停用");
            }
            responseList.add(response);
        }
        logger.info("根据条件分页查询企业的H5内容服务方案:" + JSON.toJSONString(responseList));
        //成功：给前端统一返回
        return ResultDataDto.addOperationSuccess().setData(responseList).setPageAndSort(pageHelper);
    }


    /***
     * 新建方案一：查询流量
     * @param request
     * @param token
     * @return
     */
    @Override
    public ResultDataDto firstPlanCreate(RequestFirstPlanCreate request, MultipartFile fileListPc, MultipartFile fileListPh, String token) {

        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        //1,先去公共服务类验证token
        String results = utilsService.checkAdmin(token);

        if (StringUtils.isBlank(results) || !StringOutputConstant.CODE_SUCCESS.equals(results)) {
            // 验证token出现问题，直接返回
            return ResultDataDto.addOperationFailure(results);
        }

        //确认安全，开始验证参数
        if (StringUtils.isBlank(request.getTradeType()) || StringUtils.isBlank(request.getLang()) || StringUtils.isBlank(request.getVersion()) ||
                StringUtils.isBlank(request.getPartnerCode()) || StringUtils.isBlank(request.getConfigType()) ||
                StringUtils.isBlank(request.getShowContent()) || null == request.getLinkURL() || null == request.getFirstLangText()) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_ERROR);
        }

        //2，准备2个数组，分别允许下一步（1）或者不允许（0）的结果码
        List<String> list1 = new ArrayList<String>();
        List<String> list2 = new ArrayList<String>();
        for (FirstPlanLangTextConfig lang : request.getFirstLangText()) {
            if (StringUtils.isNotBlank(lang.getLanguageCode()) && StringUtils.isNotBlank(lang.getLanguageName()) && StringUtils.isNotBlank(lang.getLanguagePriority()) && null != lang.getWelcomeLang()) {
                list1.add("1");
            } else {
                list2.add("0");
            }
        }

        if (list1.isEmpty() || !list2.isEmpty()) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_LANG_ERROR);
        }

        if (!request.getConfigType().equals("1")) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_CONFIG_ERROR);
        }

        //查到企业名称
        String partnerName = configMapper.queryNameByCode(request.getPartnerCode());
        //生成方案编码
        String planCode = sequenceService.getSevicePlanCodeNo();

        //语言配置内容添加成功，才可进行下一步
        //入库：partner_config_content_t
        Integer c = utilsService.planCreateConfigContent(planCode, request.getPartnerCode(), partnerName, request.getConfigType(), "1", request.getShowContent(), request.getLinkURL(), "0", fileListPc, fileListPh);

        if (c <= 0) {
            // 存储数据遇到了问题
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_STORE_CONFIG_ERROR);
        }

        Integer count = 0;
        for (FirstPlanLangTextConfig la : request.getFirstLangText()) {
            //语言配置内容入库
            //入库：partner_config_lang_t
            count = utilsService.planCreateConfigLang(planCode, la.getLanguageCode(), la.getLanguageName(), la.getLanguagePriority(), la.getWelcomeLang(), request.getPartnerCode(), request.getConfigType(), "");
        }

        if (count <= 0) {
            // 存储数据遇到了问题
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_STORE_LANG_ERROR);
        }

        //成功：给前端统一返回
        return ResultDataDto.addOperationSuccess("成功");
    }

    /***
     *新建方案二：联系商家
     * @param request
     * @param token
     * @return
     */
    @Override
    public ResultDataDto secondPlanCreate(RequestSecondPlanCreate request, MultipartFile fileListPc, MultipartFile fileListPh, String token) {

        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        //1,先去公共服务类验证token
        String results = utilsService.checkAdmin(token);

        if (StringUtils.isBlank(results) || !StringOutputConstant.CODE_SUCCESS.equals(results)) {
            // 验证token出现问题，直接返回
            return ResultDataDto.addOperationFailure(results);
        }

        //确认安全，开始验证参数
        if (StringUtils.isBlank(request.getTradeType()) || StringUtils.isBlank(request.getLang()) || StringUtils.isBlank(request.getVersion()) ||
                StringUtils.isBlank(request.getPartnerCode()) || StringUtils.isBlank(request.getConfigType()) ||
                null == request.getSecondLangText()) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_ERROR);
        }

        //2，准备2个数组，分别允许下一步（1）或者不允许（0）的结果码
        List<String> list1 = new ArrayList<String>();
        List<String> list2 = new ArrayList<String>();

        for (SecondPlanLangTextConfig lang : request.getSecondLangText()) {
            if (StringUtils.isNotBlank(lang.getLanguageCode()) && StringUtils.isNotBlank(lang.getLanguageName()) && StringUtils.isNotBlank(lang.getLanguagePriority()) &&
                    StringUtils.isNotBlank(lang.getPopupContent()) && null != lang.getWelcomeLang()) {
                list1.add("1");
            } else {
                list2.add("0");
            }
        }

        if (list1.isEmpty() || !list2.isEmpty()) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_LANG_ERROR);
        }

        if (!request.getConfigType().equals("2")) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_CONFIG_ERROR);
        }

        //先建好方案再往下
        //查到企业名称
        String partnerName = configMapper.queryNameByCode(request.getPartnerCode());
        //生成方案编码
        String planCode = sequenceService.getSevicePlanCodeNo();

        //语言配置内容添加成功，才可进行下一步
        Integer c = utilsService.planCreateConfigContent(planCode, request.getPartnerCode(), partnerName, request.getConfigType(), "1", "", "", "0", fileListPc, fileListPh);

        if (c <= 0) {
            //新建方案遇到了问题
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_STORE_CONFIG_ERROR);
        }

        Integer count = 0;
        for (SecondPlanLangTextConfig la : request.getSecondLangText()) {
            //语言配置内容入库
            //入库：partner_config_lang_t
            count = utilsService.planCreateConfigLang(planCode, la.getLanguageCode(), la.getLanguageName(), la.getLanguagePriority(), la.getWelcomeLang(), request.getPartnerCode(), request.getConfigType(), la.getPopupContent());
        }

        if (count <= 0) {
            // 存储数据遇到了问题
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_STORE_LANG_ERROR);
        }

        //成功：给前端统一返回
        return ResultDataDto.addOperationSuccess("成功");

    }

    /***
     *新建方案三：跳转商家
     * @param request
     * @param token
     * @return
     */
    @Override
    public ResultDataDto thirdPlanCreate(RequestThirdPlanCreate request, MultipartFile fileListPc, MultipartFile fileListPh, String token) {

        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        //1,先去公共服务类验证token
        String results = utilsService.checkAdmin(token);

        if (StringUtils.isBlank(results) || !StringOutputConstant.CODE_SUCCESS.equals(results)) {
            // 验证token出现问题，直接返回
            return ResultDataDto.addOperationFailure(results);
        }

        //确认安全，开始验证参数
        if (StringUtils.isBlank(request.getTradeType()) || StringUtils.isBlank(request.getLang()) || StringUtils.isBlank(request.getVersion()) ||
                StringUtils.isBlank(request.getPartnerCode()) || StringUtils.isBlank(request.getConfigType()) ||
                StringUtils.isBlank(request.getLinkURL()) || null == request.getThirdLangText()) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_ERROR);
        }

        //2，准备2个数组，分别允许下一步（1）或者不允许（0）的结果码
        List<String> list1 = new ArrayList<String>();
        List<String> list2 = new ArrayList<String>();
        for (ThirdPlanLangTextConfig lang : request.getThirdLangText()) {
            if (StringUtils.isNotBlank(lang.getLanguageCode()) && StringUtils.isNotBlank(lang.getLanguageName()) && StringUtils.isNotBlank(lang.getLanguagePriority()) && null != lang.getWelcomeLang()) {
                list1.add("1");
            } else {
                list2.add("0");
            }
        }

        if (list1.isEmpty() || !list2.isEmpty()) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_LANG_ERROR);
        }


        if (!request.getConfigType().equals("3")) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_CONFIG_ERROR);
        }

        //先建方案
        //查到企业名称
        String partnerName = configMapper.queryNameByCode(request.getPartnerCode());
        //生成方案编码
        String planCode = sequenceService.getSevicePlanCodeNo();
        //方案内容配置入库
        //入库：partner_config_content_t
        Integer c = utilsService.planCreateConfigContent(planCode, request.getPartnerCode(), partnerName, request.getConfigType(), "1", "", request.getLinkURL(), "0", fileListPc, fileListPh);

        if (c <= 0) {
            //新建方案遇到了问题
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_STORE_CONFIG_ERROR);
        }


        Integer count = 0;

        for (ThirdPlanLangTextConfig la : request.getThirdLangText()) {
            //语言配置内容入库
            //入库：partner_config_lang_t
            count = utilsService.planCreateConfigLang(planCode, la.getLanguageCode(), la.getLanguageName(), la.getLanguagePriority(), la.getWelcomeLang(), request.getPartnerCode(), request.getConfigType(), "");
        }
        if (count <= 0) {
            // 存储数据遇到了问题
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_STORE_LANG_ERROR);
        }


        //成功：给前端统一返回
        return ResultDataDto.addOperationSuccess("成功");
    }

    /***
     *新建方案四：直接订购
     * @param request
     * @param token
     * @return
     */
    @Override
    public ResultDataDto fourthPlanCreate(RequestFourthPlanCreate request, MultipartFile fileListPc, MultipartFile fileListPh, String token) {

        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        //1,先去公共服务类验证token
        String results = utilsService.checkAdmin(token);

        if (StringUtils.isBlank(results) || !StringOutputConstant.CODE_SUCCESS.equals(results)) {
            // 验证token出现问题，直接返回
            return ResultDataDto.addOperationFailure(results);
        }
        //确认安全，开始验证参数
        if (StringUtils.isBlank(request.getTradeType()) || StringUtils.isBlank(request.getLang()) || StringUtils.isBlank(request.getVersion()) ||
                StringUtils.isBlank(request.getPartnerCode()) || StringUtils.isBlank(request.getConfigType()) ||
                StringUtils.isBlank(request.getPayConfig()) || null == request.getFourthLangText() || null == request.getPayText()) {

            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_ERROR);
        }

        //2，准备2个数组，分别允许下一步（1）或者不允许（0）的结果码
        List<String> list1 = new ArrayList<String>();
        List<String> list2 = new ArrayList<String>();
        for (FourthPlanLangTextConfig lang : request.getFourthLangText()) {
            if (StringUtils.isNotBlank(lang.getLanguageCode()) && StringUtils.isNotBlank(lang.getLanguageName()) && StringUtils.isNotBlank(lang.getLanguagePriority()) && null != lang.getWelcomeLang()) {
                list1.add("1");
            } else {
                list2.add("0");
            }
        }

        //3，判断上面上面的遍历结果是全部允许（1）还是有存在不允许（0）
        if (list1.isEmpty() || !list2.isEmpty()) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_LANG_ERROR);
        }

        if (!request.getConfigType().equals("4")) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_CONFIG_ERROR);
        }

        //先建方案：
        //查到企业名称
        String partnerName = configMapper.queryNameByCode(request.getPartnerCode());
        //生成方案编码
        String planCode = sequenceService.getSevicePlanCodeNo();

        //语言配置内容添加成功，才可进行下一步
        //入库：partner_config_content_t
        Integer c = utilsService.planCreateConfigContent(planCode, request.getPartnerCode(), partnerName, request.getConfigType(), "1", "", "", request.getPayConfig(), fileListPc, fileListPh);

        if (c <= 0) {
            //新建方案遇到了问题
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_STORE_CONFIG_ERROR);
        }

        //方案建好无误再去做语言和支付配置入库

        if (request.getPayConfig().equals("1")) {
            //有支付配置
            //3，准备2个数组，分别允许下一步（1）或者不允许（0）的结果码
            List<String> list3 = new ArrayList<String>();
            List<String> list4 = new ArrayList<String>();

            FourthPlanPayTextConfig pay = request.getPayText();

            if (StringUtils.isNotBlank(pay.getPayType()) && StringUtils.isNotBlank(pay.getMode()) && StringUtils.isNotBlank(pay.getClientId()) && StringUtils.isNotBlank(pay.getClientSecret())) {
                list3.add("1");
            } else {
                list4.add("0");
            }

            if (list3.isEmpty() || !list4.isEmpty()) {
                return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_PAY_ERROR);
            }

            //4，判断上面上面的遍历结果是全部允许（1）还是有存在不允许（0）
            //支付配置内容入库
            utilsService.planCreateConfigPay(planCode, request.getPartnerCode(), pay.getPayType(), pay.getMode(), pay.getClientId(), pay.getClientSecret());

        }

        Integer langCount = 0;

        for (FourthPlanLangTextConfig la : request.getFourthLangText()) {
            //语言配置内容入库
            //入库：partner_config_lang_t
            langCount = utilsService.planCreateConfigLang(planCode, la.getLanguageCode(), la.getLanguageName(), la.getLanguagePriority(), la.getWelcomeLang(), request.getPartnerCode(), request.getConfigType(), "");
        }

        if (langCount <= 0) {
            // 存储数据遇到了问题
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_STORE_LANG_ERROR);
        }

        //成功：给前端统一返回
        return ResultDataDto.addOperationSuccess("成功");
    }

    /***
     *H5功能管理：查看：方案一
     * @param request
     * @param token
     * @return
     */
    @Override
    public ResultDataDto firstPlanView(RequestContentPlanView request, String token) {

        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        //1,先去公共服务类验证token
        String results = utilsService.checkAdmin(token);

        if (StringUtils.isBlank(results) || !StringOutputConstant.CODE_SUCCESS.equals(results)) {
            // 验证token出现问题，直接返回
            return ResultDataDto.addOperationFailure(results);
        }

        //确认安全，开始验证参数
        if (StringUtils.isBlank(request.getTradeType()) || StringUtils.isBlank(request.getLang()) || StringUtils.isBlank(request.getVersion()) ||
                StringUtils.isBlank(request.getPartnerCode()) || StringUtils.isBlank(request.getConfigType()) || StringUtils.isBlank(request.getPlanCode())) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_ERROR);
        }

        //1,查询到语言信息相关：
        List<PartnerConfigLang> langList = configMapper.queryLangConfig(request.getPlanCode(), request.getPartnerCode(), request.getConfigType());

        //2，整理语言配置方面的信息
        List<FirstPlanLangConfig> langConfigList = new ArrayList<FirstPlanLangConfig>();

        FirstPlanLangConfig langConfig = null;

        for (PartnerConfigLang lang : langList) {
            langConfig = new FirstPlanLangConfig();
            langConfig.setLanguageCode(lang.getLanguageCode());
            langConfig.setLanguageName(lang.getLanguageName());
            langConfig.setLanguagePriority(lang.getLanguagePriority());
            langConfig.setWelcomeLang(lang.getWelcomeLang());
            langConfigList.add(langConfig);
        }

        //3,查询显示内容中的具体参数:
        List<PartnerConfigContent> contentList = configMapper.queryContentConfig(request.getPlanCode(), request.getPartnerCode(), request.getConfigType());

        // 字符串转数组  java.lang.String;String str = "0,1,2,3,4,5";String[] arr = str.split(","); // 用,分割;System.out.println(Arrays.toString(arr));[0, 1, 2, 3, 4, 5]

        ResponseFirstPlanView response = null;

        for (PartnerConfigContent content : contentList) {
            response = new ResponseFirstPlanView();
            response.setPartnerCode(content.getPartnerCode());
            response.setPartnerName(content.getPartnerName());
            response.setConfigType(content.getConfigType());
            response.setConfigStatus(content.getConfigStatus());
            response.setPlanCode(content.getPlanCode());
            response.setLinkURL(content.getLinkURL());
            response.setPcBgimg(content.getPcBgimg());
            response.setPhBgimg(content.getPhBgimg());
            response.setShowContent(content.getShowContent().split(","));
            response.setFirstLangView(langConfigList);
        }
        logger.info("方案一查看：" + JSON.toJSONString(response));
        //4，成功返回
        return ResultDataDto.addOperationSuccess().setData(response);
    }

    /***
     *H5功能管理：查看：方案二
     * @param request
     * @param token
     * @return
     */
    @Override
    public ResultDataDto secondPlanView(RequestContentPlanView request, String token) {

        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        //1,先去公共服务类验证token
        String results = utilsService.checkAdmin(token);

        if (StringUtils.isBlank(results) || !StringOutputConstant.CODE_SUCCESS.equals(results)) {
            // 验证token出现问题，直接返回
            return ResultDataDto.addOperationFailure(results);
        }


        //确认安全，开始验证参数
        if (StringUtils.isBlank(request.getTradeType()) || StringUtils.isBlank(request.getLang()) || StringUtils.isBlank(request.getVersion()) ||
                StringUtils.isBlank(request.getPartnerCode()) || StringUtils.isBlank(request.getConfigType()) || StringUtils.isBlank(request.getPlanCode())) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_ERROR);
        }

        //1,查询到语言信息相关：
        List<PartnerConfigLang> langList = configMapper.queryLangConfig(request.getPlanCode(), request.getPartnerCode(), request.getConfigType());

        //2，整理语言配置方面的信息
        List<SecondPlanLangConfig> langConfigList = new ArrayList<SecondPlanLangConfig>();
        SecondPlanLangConfig langConfig = null;

        for (PartnerConfigLang lang : langList) {
            langConfig = new SecondPlanLangConfig();
            langConfig.setLanguageCode(lang.getLanguageCode());
            langConfig.setLanguageName(lang.getLanguageName());
            langConfig.setLanguagePriority(lang.getLanguagePriority());
            langConfig.setWelcomeLang(lang.getWelcomeLang());
            langConfig.setPopupContent(lang.getPopupContent());
            langConfigList.add(langConfig);
        }

        //3,查询显示内容中的具体参数:
        List<PartnerConfigContent> contentList = configMapper.queryContentConfig(request.getPlanCode(), request.getPartnerCode(), request.getConfigType());

        ResponseSecondPlanView response = null;
        for (PartnerConfigContent content : contentList) {
            response = new ResponseSecondPlanView();
            response.setPartnerCode(content.getPartnerCode());
            response.setPartnerName(content.getPartnerName());
            response.setPlanCode(content.getPlanCode());
            response.setConfigType(content.getConfigType());
            response.setConfigStatus(content.getConfigStatus());
            response.setPcBgimg(content.getPcBgimg());
            response.setPhBgimg(content.getPhBgimg());
            response.setSecondLangView(langConfigList);
        }
        logger.info("方案二查看：" + JSON.toJSONString(response));
        //4，成功返回
        return ResultDataDto.addOperationSuccess().setData(response);
    }

    /***
     *H5功能管理：查看：方案三
     * @param request
     * @param token
     * @return
     */
    @Override
    public ResultDataDto thirdPlanView(RequestContentPlanView request, String token) {

        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        //1,先去公共服务类验证token
        String results = utilsService.checkAdmin(token);

        if (StringUtils.isBlank(results) || !StringOutputConstant.CODE_SUCCESS.equals(results)) {
            // 验证token出现问题，直接返回
            return ResultDataDto.addOperationFailure(results);
        }

        //确认安全，开始验证参数
        if (StringUtils.isBlank(request.getTradeType()) || StringUtils.isBlank(request.getLang()) || StringUtils.isBlank(request.getVersion()) ||
                StringUtils.isBlank(request.getPartnerCode()) || StringUtils.isBlank(request.getConfigType()) || StringUtils.isBlank(request.getPlanCode())) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_ERROR);
        }

        //1,查询到语言信息相关：
        List<PartnerConfigLang> langList = configMapper.queryLangConfig(request.getPlanCode(), request.getPartnerCode(), request.getConfigType());

        //2，整理语言配置方面的信息
        List<ThirdPlanLangConfig> langConfigList = new ArrayList<ThirdPlanLangConfig>();
        ThirdPlanLangConfig langConfig = null;

        for (PartnerConfigLang lang : langList) {
            langConfig = new ThirdPlanLangConfig();
            langConfig.setLanguageCode(lang.getLanguageCode());
            langConfig.setLanguageName(lang.getLanguageName());
            langConfig.setLanguagePriority(lang.getLanguagePriority());
            langConfig.setWelcomeLang(lang.getWelcomeLang());
            langConfigList.add(langConfig);
        }

        //3,查询显示内容中的具体参数:
        List<PartnerConfigContent> contentList = configMapper.queryContentConfig(request.getPlanCode(), request.getPartnerCode(), request.getConfigType());

        ResponseThirdPlanView response = null;
        for (PartnerConfigContent content : contentList) {

            response = new ResponseThirdPlanView();
            response.setPartnerCode(content.getPartnerCode());
            response.setPartnerName(content.getPartnerName());
            response.setConfigType(content.getConfigType());
            response.setConfigStatus(content.getConfigStatus());
            response.setPartnerCode(content.getPlanCode());
            response.setPcBgimg(content.getPcBgimg());
            response.setPhBgimg(content.getPhBgimg());
            response.setLinkURL(content.getLinkURL());
            response.setThirdLangView(langConfigList);
        }

        logger.info("方案三查看：" + JSON.toJSONString(response));
        //4，成功返回
        return ResultDataDto.addOperationSuccess().setData(response);
    }

    /***
     *H5功能管理：查看：方案四
     * @param request
     * @param token
     * @return
     */
    @Override
    public ResultDataDto fourthPlanView(RequestContentPlanView request, String token) {

        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        //1,先去公共服务类验证token
        String results = utilsService.checkAdmin(token);

        if (StringUtils.isBlank(results) || !StringOutputConstant.CODE_SUCCESS.equals(results)) {
            // 验证token出现问题，直接返回
            return ResultDataDto.addOperationFailure(results);
        }

        //确认安全，开始验证参数
        if (StringUtils.isBlank(request.getTradeType()) || StringUtils.isBlank(request.getLang()) || StringUtils.isBlank(request.getVersion()) ||
                StringUtils.isBlank(request.getPartnerCode()) || StringUtils.isBlank(request.getConfigType()) || StringUtils.isBlank(request.getPlanCode())) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_ERROR);
        }

        //1,查询到语言信息相关：
        List<PartnerConfigLang> langList = configMapper.queryLangConfig(request.getPlanCode(), request.getPartnerCode(), request.getConfigType());

        //2，整理语言配置方面的信息
        List<FourthPlanLangConfig> langConfigList = new ArrayList<FourthPlanLangConfig>();
        FourthPlanLangConfig langConfig = null;

        for (PartnerConfigLang lang : langList) {
            langConfig = new FourthPlanLangConfig();
            langConfig.setLanguageCode(lang.getLanguageCode());
            langConfig.setLanguageName(lang.getLanguageName());
            langConfig.setLanguagePriority(lang.getLanguagePriority());
            langConfig.setWelcomeLang(lang.getWelcomeLang());
            langConfigList.add(langConfig);
        }

        //3,查询显示内容中的具体参数:
        List<PartnerConfigContent> contentList = configMapper.queryContentConfig(request.getPlanCode(), request.getPartnerCode(), request.getConfigType());

        ResponseFourthPlanView response = null;

        for (PartnerConfigContent content : contentList) {

            FourthPlanPayConfig payConfig = null;

            if (content.getPayConfig().equals("1")) {
                //4，根据partnerCode 和 configType查询是否有支付配置
                List<PartnerConfigPay> payList = configMapper.queryPayConfig(request.getPartnerCode());

                for (PartnerConfigPay configPay : payList) {

                    payConfig = new FourthPlanPayConfig();
                    payConfig.setPayType(configPay.getPayType());
                    payConfig.setMode(configPay.getMode());
                    payConfig.setClientId(configPay.getClientId());
                    payConfig.setClientSecret(configPay.getClientSecret());
                }
            }

            //5，返回
            response = new ResponseFourthPlanView();
            response.setPartnerCode(content.getPartnerCode());
            response.setPartnerName(content.getPartnerName());
            response.setConfigType(content.getConfigType());
            response.setConfigStatus(content.getConfigStatus());
            response.setPlanCode(content.getPlanCode());
            response.setPcBgimg(content.getPcBgimg());
            response.setPhBgimg(content.getPhBgimg());
            response.setPayConfig(content.getPayConfig());
            response.setFourthLangView(langConfigList);
            response.setPayView(payConfig);
        }

        logger.info("方案四查看：" + JSON.toJSONString(response));
        //6，成功返回
        return ResultDataDto.addOperationSuccess().setData(response);
    }

    /***
     * H5功能管理：所有语种服务列表
     * @param request
     * @param token
     * @return
     */
    @Override
    public ResultDataDto langList(RequestLangList request, String token) {

        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        //1,先去公共服务类验证token
        String results = utilsService.checkAdmin(token);

        if (StringUtils.isBlank(results) || !StringOutputConstant.CODE_SUCCESS.equals(results)) {
            // 验证token出现问题，直接返回
            return ResultDataDto.addOperationFailure(results);
        }

        //确认安全，开始验证参数
        if (StringUtils.isBlank(request.getTradeType()) || StringUtils.isBlank(request.getLang()) || StringUtils.isBlank(request.getVersion())) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_ERROR);

        }
        //1,查询到语言信息相关：
        List<LanguageType> langlist = configMapper.queryLangList();

        List<ResponseLangList> responseLangListList = new ArrayList<ResponseLangList>();

        for (LanguageType lang : langlist) {

            ResponseLangList response = new ResponseLangList();
            response.setLanguageCode(lang.getLanguageCode());
            response.setLanguageName(lang.getLanguageName());
            response.setLanguageStatus(lang.getLanguageStatus());

            responseLangListList.add(response);
        }
        logger.info("语种服务列表返回：" + JSON.toJSONString(responseLangListList));
        //2,成功返回
        return ResultDataDto.addOperationSuccess().setData(responseLangListList);
    }

    /***
     * 方案一：语言文本配置编辑：
     * 语言选择之后不允许编辑 ：优先级和欢迎语可以编辑
     * @param request
     * @param token
     * @return
     */
    @Override
    public ResultDataDto firstLangEdit(RequestFirstLangEdit request, String token) {

        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        //1,先去公共服务类验证token
        String results = utilsService.checkAdmin(token);

        if (StringUtils.isBlank(results) || !StringOutputConstant.CODE_SUCCESS.equals(results)) {
            // 验证token出现问题，直接返回
            return ResultDataDto.addOperationFailure(results);
        }
        //1，确认安全，开始验证参数
        if (StringUtils.isBlank(request.getTradeType()) || StringUtils.isBlank(request.getLang()) || StringUtils.isBlank(request.getVersion()) ||
                StringUtils.isBlank(request.getPartnerCode()) || StringUtils.isBlank(request.getConfigType()) || StringUtils.isBlank(request.getConfigStatus()) ||
                StringUtils.isBlank(request.getPlanCode()) || null == request.getFirstLangEdit()) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_ERROR);
        }

        //2，准备2个数组，分别允许下一步（1）或者不允许（0）的结果码
        List<String> list1 = new ArrayList<String>();
        List<String> list2 = new ArrayList<String>();

        for (FirstPlanLangEdit lang : request.getFirstLangEdit()) {
            if (StringUtils.isNotBlank(lang.getLanguageCode()) && StringUtils.isNotBlank(lang.getLanguageName()) && StringUtils.isNotBlank(lang.getLanguagePriority()) && null != lang.getWelcomeLang()) {
                list1.add("1");
            } else {
                list2.add("0");
            }
        }

        if (list1.isEmpty() || !list2.isEmpty()) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_LANG_ERROR);
        }

        if (!request.getConfigType().equals("1") || request.getConfigStatus().equals("2")) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_CONFIG_ERROR);
        }

        //3，判断上面上面的遍历结果是全部允许（1）还是有存在不允许（0）
        //方案一且状态是不是已启用才可以继续操作
        Integer contCount = configMapper.queryContentCount(request.getPlanCode(), request.getPartnerCode(), request.getConfigType(), request.getConfigStatus());

        Integer langCount = configMapper.queryLangCount(request.getPlanCode(), request.getPartnerCode(), request.getConfigType());

        if (contCount <= 0 || langCount <= 0) {
            //指令有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_ERROR);
        }
        Integer count = 0;

        //语言编辑结束
        for (FirstPlanLangEdit la : request.getFirstLangEdit()) {
            //编辑语言配置内容
            //更新数据表：partner_config_lang_t
            count = utilsService.editPlanConfigLang(request.getPlanCode(), la.getLanguageCode(), la.getLanguageName(), la.getLanguagePriority(), la.getWelcomeLang(), request.getPartnerCode(), request.getConfigType(), "");
        }

        //需要通知方案更新updateDate的时间
        utilsService.updateConfigContentDate(request.getPlanCode(), request.getPartnerCode());

        //4，准备2个数组，分别成功（1）或者不成功（0）的结果码
        List<String> list3 = new ArrayList<String>();
        List<String> list4 = new ArrayList<String>();
        if (count > 0) {
            list3.add("1");
        } else {
            list4.add("0");
        }
        if (list3.isEmpty() || !list4.isEmpty()) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_LANG_EDIT_ERROR);
        }
        //成功返回
        return ResultDataDto.addOperationSuccess("成功");
    }

    /***
     * 方案一：内容文本配置编辑：
     * 跳转URL地址，显示内容 两项可以编辑
     * @param request
     * @param token
     * @return
     */
    @Override
    public ResultDataDto firstContentEdit(RequestFirstContentEdit request, String token, MultipartFile fileListPc, MultipartFile fileListPh) {

        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        //1,先去公共服务类验证token
        String results = utilsService.checkAdmin(token);

        if (StringUtils.isBlank(results) || !StringOutputConstant.CODE_SUCCESS.equals(results)) {
            // 验证token出现问题，直接返回
            return ResultDataDto.addOperationFailure(results);
        }

        //1，确认安全，开始验证参数
        if (StringUtils.isBlank(request.getTradeType()) || StringUtils.isBlank(request.getLang()) || StringUtils.isBlank(request.getVersion()) ||
                StringUtils.isBlank(request.getPartnerCode()) || StringUtils.isBlank(request.getConfigType()) || StringUtils.isBlank(request.getConfigStatus()) ||
                StringUtils.isBlank(request.getShowContent()) || null == request.getLinkURL() || StringUtils.isBlank(request.getPlanCode())) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_ERROR);
        }

        if (!request.getConfigType().equals("1") || request.getConfigStatus().equals("2")) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_CONFIG_ERROR);
        }

        //方案一且状态是不是已启用才可以继续操作
        Integer contCount = configMapper.queryContentCount(request.getPlanCode(), request.getPartnerCode(), request.getConfigType(), request.getConfigStatus());

        if (contCount <= 0) {
            //指令有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_ERROR);
        }
        //编辑：方案一内容配置
        Integer count = utilsService.editPlanConfigContent(request.getPlanCode(), request.getPartnerCode(), request.getConfigType(), request.getConfigStatus(), request.getShowContent(), request.getLinkURL(), fileListPc, fileListPh);

        if (count <= 0) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_CONTENT_EDIT_ERROR);
        }
        //成功返回
        return ResultDataDto.addOperationSuccess("成功");
    }

    /***
     * 方案二：语言文本配置编辑：
     * 语言选择之后不允许编辑 ：优先级和欢迎语以及弹窗内容可以编辑
     * @param request
     * @param token
     * @return
     */
    @Override
    public ResultDataDto secondLangEdit(RequestSecondLangEdit request, String token) {

        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        //1,先去公共服务类验证token
        String results = utilsService.checkAdmin(token);

        if (StringUtils.isBlank(results) || !StringOutputConstant.CODE_SUCCESS.equals(results)) {
            // 验证token出现问题，直接返回
            return ResultDataDto.addOperationFailure(results);
        }

        //1，确认安全，开始验证参数
        if (StringUtils.isBlank(request.getTradeType()) || StringUtils.isBlank(request.getLang()) || StringUtils.isBlank(request.getVersion()) ||
                StringUtils.isBlank(request.getPartnerCode()) || StringUtils.isBlank(request.getConfigType()) || StringUtils.isBlank(request.getConfigStatus()) ||
                StringUtils.isBlank(request.getPlanCode()) || null == request.getSecondLangEdit()) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_ERROR);
        }

        //2，准备2个数组，分别允许下一步（1）或者不允许（0）的结果码
        List<String> list1 = new ArrayList<String>();
        List<String> list2 = new ArrayList<String>();
        for (SecondPlanLangEdit lang : request.getSecondLangEdit()) {
            if (StringUtils.isNotBlank(lang.getLanguageCode()) && StringUtils.isNotBlank(lang.getLanguageName()) && StringUtils.isNotBlank(lang.getLanguagePriority()) && null != lang.getWelcomeLang() && StringUtils.isNotBlank(lang.getPopupContent())) {
                list1.add("1");
            } else {
                list2.add("0");
            }
        }

        if (list1.isEmpty() || !list2.isEmpty()) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_LANG_ERROR);
        }

        if (!request.getConfigType().equals("2") || request.getConfigStatus().equals("2")) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_CONFIG_ERROR);
        }

        //方案一且状态是不是已启用才可以继续操作

        Integer contCount = configMapper.queryContentCount(request.getPlanCode(), request.getPartnerCode(), request.getConfigType(), request.getConfigStatus());

        Integer langCount = configMapper.queryLangCount(request.getPlanCode(), request.getPartnerCode(), request.getConfigType());

        if (contCount <= 0 || langCount <= 0) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_ERROR);
        }

        Integer count = 0;

        for (SecondPlanLangEdit la : request.getSecondLangEdit()) {
            //编辑语言配置内容
            //更新数据表：partner_config_lang_t
            count = utilsService.editPlanConfigLang(request.getPlanCode(), la.getLanguageCode(), la.getLanguageName(), la.getLanguagePriority(), la.getWelcomeLang(), request.getPartnerCode(), request.getConfigType(), la.getPopupContent());
        }

        //需要通知方案更新updateDate的时间
        utilsService.updateConfigContentDate(request.getPlanCode(), request.getPartnerCode());

        //4，准备2个数组，分别成功（1）或者不成功（0）的结果码
        List<String> list3 = new ArrayList<String>();
        List<String> list4 = new ArrayList<String>();
        if (count > 0) {
            list3.add("1");
        } else {
            list4.add("0");
        }
        if (list3.isEmpty() || !list4.isEmpty()) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_LANG_EDIT_ERROR);
        }
        //成功返回
        return ResultDataDto.addOperationSuccess("成功");
    }

    /***
     * 方案二：内容编辑：
     * 不管之前新建的时候有没有，这边只用判断file是不是传了文件
     * @param partnerCode
     * @param configType
     * @param configStatus
     * @param token
     * @param file
     * @return
     */
    @Override
    public ResultDataDto secondContentEdit(RequestSecondContentEdit request, String token, MultipartFile fileListPc, MultipartFile fileListPh) {

        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        //1,先去公共服务类验证token
        String results = utilsService.checkAdmin(token);

        if (StringUtils.isBlank(results) || !StringOutputConstant.CODE_SUCCESS.equals(results)) {
            // 验证token出现问题，直接返回
            return ResultDataDto.addOperationFailure(results);
        }

        //1，确认安全，开始验证参数
        if (StringUtils.isBlank(request.getPartnerCode()) || StringUtils.isBlank(request.getConfigType()) || StringUtils.isBlank(request.getConfigStatus()) ||
                StringUtils.isBlank(request.getLang()) || StringUtils.isBlank(request.getTradeType()) || StringUtils.isBlank(request.getVersion()) || StringUtils.isBlank(request.getPlanCode()) ||
                null == fileListPc || fileListPc.isEmpty() || null == fileListPh || fileListPh.isEmpty()) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_ERROR);
        }

        Integer contCount = configMapper.queryContentCount(request.getPlanCode(), request.getPartnerCode(), request.getConfigType(), request.getConfigStatus());

        if (contCount <= 0) {
            //指令有误，请联系管理员
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_ERROR);
        }

        if (!request.getConfigType().equals("2") || request.getConfigStatus().equals("2")) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_CONFIG_ERROR);
        }

        //编辑：背景图片更改方案
        Integer count = utilsService.secondContentEdit(request.getPlanCode(), request.getPartnerCode(), request.getConfigType(), request.getConfigStatus(), fileListPc, fileListPh);

        if (count <= 0) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_BGM_ERROR);
        }
        //成功返回
        return ResultDataDto.addOperationSuccess("成功");
    }

    /***
     * 方案三：语言文本配置编辑：
     * 语言选择之后不允许编辑 ：优先级和欢迎语可以编辑
     * @param request
     * @param token
     * @return
     */
    @Override
    public ResultDataDto thirdLangEdit(RequestThirdLangEdit request, String token) {

        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        //1,先去公共服务类验证token
        String results = utilsService.checkAdmin(token);

        if (StringUtils.isBlank(results) || !StringOutputConstant.CODE_SUCCESS.equals(results)) {
            // 验证token出现问题，直接返回
            return ResultDataDto.addOperationFailure(results);
        }
        //1，确认安全，开始验证参数
        if (StringUtils.isBlank(request.getTradeType()) || StringUtils.isBlank(request.getLang()) || StringUtils.isBlank(request.getVersion()) ||
                StringUtils.isBlank(request.getPartnerCode()) || StringUtils.isBlank(request.getConfigType()) || StringUtils.isBlank(request.getConfigStatus()) ||
                StringUtils.isBlank(request.getPlanCode()) || null == request.getThirdLangEdit()) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_ERROR);
        }

        //2，准备2个数组，分别允许下一步（1）或者不允许（0）的结果码
        List<String> list1 = new ArrayList<String>();
        List<String> list2 = new ArrayList<String>();

        for (ThirdPlanLangEdit lang : request.getThirdLangEdit()) {
            if (StringUtils.isNotBlank(lang.getLanguageCode()) && StringUtils.isNotBlank(lang.getLanguageName()) && StringUtils.isNotBlank(lang.getLanguagePriority()) && null != lang.getWelcomeLang()) {
                list1.add("1");
            } else {
                list2.add("0");
            }
        }

        if (list1.isEmpty() || !list2.isEmpty()) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_LANG_ERROR);
        }

        if (!request.getConfigType().equals("3") || request.getConfigStatus().equals("2")) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_CONFIG_ERROR);
        }
        //方案三且状态是不是已启用才可以继续操作


        Integer contCount = configMapper.queryContentCount(request.getPlanCode(), request.getPartnerCode(), request.getConfigType(), request.getConfigStatus());

        Integer langCount = configMapper.queryLangCount(request.getPlanCode(), request.getPartnerCode(), request.getConfigType());

        if (contCount <= 0 || langCount <= 0) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_ERROR);
        }

        Integer count = 0;

        for (ThirdPlanLangEdit la : request.getThirdLangEdit()) {
            //编辑语言配置内容
            //更新数据表：partner_config_lang_t
            count = utilsService.editPlanConfigLang(request.getPlanCode(), la.getLanguageCode(), la.getLanguageName(), la.getLanguagePriority(), la.getWelcomeLang(), request.getPartnerCode(), request.getConfigType(), "");
        }

        //需要通知方案更新updateDate的时间
        utilsService.updateConfigContentDate(request.getPlanCode(), request.getPartnerCode());

        //4，准备2个数组，分别成功（1）或者不成功（0）的结果码
        List<String> list3 = new ArrayList<String>();
        List<String> list4 = new ArrayList<String>();
        if (count > 0) {
            list3.add("1");
        } else {
            list4.add("0");
        }

        if (list3.isEmpty() || !list4.isEmpty()) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_LANG_EDIT_ERROR);
        }
        //成功返回
        return ResultDataDto.addOperationSuccess("成功");

    }

    /***
     * 方案三：内容文本配置编辑：
     * 跳转URL地址 一项可以编辑
     * @param request
     * @param token
     * @return
     */
    @Override
    public ResultDataDto thirdContentEdit(RequestThirdContentEdit request, String token, MultipartFile fileListPc, MultipartFile fileListPh) {

        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        //1,先去公共服务类验证token
        String results = utilsService.checkAdmin(token);

        if (StringUtils.isBlank(results) || !StringOutputConstant.CODE_SUCCESS.equals(results)) {
            // 验证token出现问题，直接返回
            return ResultDataDto.addOperationFailure(results);
        }

        //1，确认安全，开始验证参数
        if (StringUtils.isBlank(request.getTradeType()) || StringUtils.isBlank(request.getLang()) || StringUtils.isBlank(request.getVersion()) ||
                StringUtils.isBlank(request.getPartnerCode()) || StringUtils.isBlank(request.getConfigType()) || StringUtils.isBlank(request.getConfigStatus()) ||
                StringUtils.isBlank(request.getLinkURL()) || StringUtils.isBlank(request.getPlanCode())) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_ERROR);
        }

        if (!request.getConfigType().equals("3") || request.getConfigStatus().equals("2")) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_CONFIG_ERROR);
        }


        Integer contCount = configMapper.queryContentCount(request.getPlanCode(), request.getPartnerCode(), request.getConfigType(), request.getConfigStatus());

        if (contCount <= 0) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_ERROR);
        }

        //编辑：方案三内容配置
        Integer count = utilsService.editPlanConfigContent(request.getPlanCode(), request.getPartnerCode(), request.getConfigType(), request.getConfigStatus(), "", request.getLinkURL(), fileListPc, fileListPh);

        if (count <= 0) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_CONTENT_EDIT_ERROR);
        }//成功返回
        return ResultDataDto.addOperationSuccess("成功");
    }

    /***
     *方案四：语言文本配置编辑：
     * 语言选择之后不允许编辑 ：优先级和欢迎语可以编辑
     * @param request
     * @param token
     * @return
     */
    @Override
    public ResultDataDto fourthLangEdit(RequestFourthLangEdit request, String token) {

        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        //1,先去公共服务类验证token
        String results = utilsService.checkAdmin(token);

        if (StringUtils.isBlank(results) || !StringOutputConstant.CODE_SUCCESS.equals(results)) {
            // 验证token出现问题，直接返回
            return ResultDataDto.addOperationFailure(results);
        }


        //1，确认安全，开始验证参数
        if (StringUtils.isBlank(request.getTradeType()) || StringUtils.isBlank(request.getLang()) || StringUtils.isBlank(request.getVersion()) ||
                StringUtils.isBlank(request.getPartnerCode()) || StringUtils.isBlank(request.getConfigType()) || StringUtils.isBlank(request.getConfigStatus()) ||
                StringUtils.isBlank(request.getPlanCode()) || null == request.getFourthLangEdit()) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_ERROR);
        }

        //2，准备2个数组，分别允许下一步（1）或者不允许（0）的结果码
        List<String> list1 = new ArrayList<String>();
        List<String> list2 = new ArrayList<String>();

        for (FourthPlanLangEdit lang : request.getFourthLangEdit()) {
            if (StringUtils.isNotBlank(lang.getLanguageCode()) && StringUtils.isNotBlank(lang.getLanguageName()) && StringUtils.isNotBlank(lang.getLanguagePriority()) && null != lang.getWelcomeLang()) {
                list1.add("1");
            } else {
                list2.add("0");
            }
        }
        if (list1.isEmpty() || !list2.isEmpty()) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_LANG_ERROR);
        }

        if (!request.getConfigType().equals("4") || request.getConfigStatus().equals("2")) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_CONFIG_ERROR);
        }


        Integer contCount = configMapper.queryContentCount(request.getPlanCode(), request.getPartnerCode(), request.getConfigType(), request.getConfigStatus());

        Integer langCount = configMapper.queryLangCount(request.getPlanCode(), request.getPartnerCode(), request.getConfigType());

        if (contCount <= 0 || langCount <= 0) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_ERROR);
        }

        Integer count = 0;

        for (FourthPlanLangEdit la : request.getFourthLangEdit()) {
            //编辑语言配置内容
            //更新数据表：partner_config_lang_t
            count = utilsService.editPlanConfigLang(request.getPlanCode(), la.getLanguageCode(), la.getLanguageName(), la.getLanguagePriority(), la.getWelcomeLang(), request.getPartnerCode(), request.getConfigType(), "");
        }

        //需要通知方案更新updateDate的时间
        utilsService.updateConfigContentDate(request.getPlanCode(), request.getPartnerCode());

        //4，准备2个数组，分别成功（1）或者不成功（0）的结果码
        List<String> list3 = new ArrayList<String>();
        List<String> list4 = new ArrayList<String>();
        if (count > 0) {
            list3.add("1");
        } else {
            list4.add("0");
        }

        if (list3.isEmpty() || !list4.isEmpty()) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_LANG_EDIT_ERROR);
        }
        //成功返回
        return ResultDataDto.addOperationSuccess("成功");


    }

    /***
     *方案四：支付配置文本编辑：
     *
     * 有勾选payConfig才有值
     * @param request
     * @param token
     * @return
     */
    @Override
    public ResultDataDto fourthContentEdit(RequestFourthPayEdit request, String token, MultipartFile fileListPc, MultipartFile fileListPh) {

        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        //1,先去公共服务类验证token
        String results = utilsService.checkAdmin(token);

        if (StringUtils.isBlank(results) || !StringOutputConstant.CODE_SUCCESS.equals(results)) {
            // 验证token出现问题，直接返回
            return ResultDataDto.addOperationFailure(results);
        }

        //1，确认安全，开始验证参数
        if (StringUtils.isBlank(request.getTradeType()) || StringUtils.isBlank(request.getLang()) || StringUtils.isBlank(request.getVersion()) ||
                StringUtils.isBlank(request.getPartnerCode()) || StringUtils.isBlank(request.getConfigType()) || StringUtils.isBlank(request.getConfigStatus()) ||
                StringUtils.isBlank(request.getPayConfig()) || StringUtils.isBlank(request.getPlanCode()) || null == request.getPayText()) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_ERROR);
        }

        if (!request.getConfigType().equals("4") || request.getConfigStatus().equals("2")) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_CONFIG_ERROR);
        }

        //方案四且状态不是已启用才可以继续操作

        Integer contCount = configMapper.queryContentCount(request.getPlanCode(), request.getPartnerCode(), request.getConfigType(), request.getConfigStatus());

        if (contCount <= 0) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_ERROR);
        }

        //编辑：方案四支付内容配置(将payConfig的值更新到内容数据表)
        Integer count = utilsService.editPayConfigContent(request.getPlanCode(), request.getPartnerCode(), request.getConfigType(), request.getConfigStatus(), request.getPayConfig(), fileListPc, fileListPh);
        if (count <= 0) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_CONTENT_EDIT_ERROR);
        }

        Integer payCount = 0;
        Integer deletePayCount = 0;

        if ("1".equals(request.getPayConfig()) && null != request.getPayText()) {
            //2，准备2个数组，分别允许下一步（1）或者不允许（0）的结果码
            List<String> list1 = new ArrayList<String>();
            List<String> list2 = new ArrayList<String>();

            FourthPlanPayEdit pay = request.getPayText();

            if (StringUtils.isNotBlank(pay.getPayType()) && StringUtils.isNotBlank(pay.getMode()) && StringUtils.isNotBlank(pay.getClientId()) && StringUtils.isNotBlank(pay.getClientSecret())) {
                list1.add("1");
            } else {
                list2.add("0");
            }

            if (list1.isEmpty() || !list2.isEmpty()) {
                // 上报的参数有误
                return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_LANG_ERROR);
            }
            //3，判断上面上面的遍历结果是全部允许（1）还是有存在不允许（0）

            //编辑支付配置内容
            //1，先去数据库里面查询是不是已经有这个配置了
            Integer parCount = configMapper.queryPayConfigCount(request.getPlanCode(), request.getPartnerCode(), pay.getPayType(), pay.getMode());

            if (parCount > 0) {

                //说明之前有记录就更新记录
                //更新数据表：partner_config_pay_t
                payCount = utilsService.editPlanConfigPay(request.getPlanCode(), request.getPartnerCode(), pay.getPayType(), pay.getMode(), pay.getClientId(), pay.getClientSecret());

            } else {
                //说明之前无记录就入库记录
                //入库数据表：partner_config_pay_t
                payCount = utilsService.planCreateConfigPay(request.getPlanCode(), request.getPartnerCode(), pay.getPayType(), pay.getMode(), pay.getClientId(), pay.getClientSecret());

            }


        } else {
            //payConfig=0，就是没有这个配置
            //1，先去数据库里面查询是不是已经有这个配置了
            Integer parCount = configMapper.queryPayCount(request.getPlanCode(), request.getPartnerCode());

            if (parCount > 0) {
                //说明之前新建过支付配置，那现在就要清空
                deletePayCount = configMapper.deletePayConfig(request.getPlanCode(), request.getPartnerCode());
            }
        }


        //3，准备2个数组，分别允许下一步（1）或者不允许（0）的结果码
        List<String> list3 = new ArrayList<String>();
        List<String> list4 = new ArrayList<String>();

        if (payCount > 0 || deletePayCount > 0) {
            list3.add("1");
        } else {
            list4.add("0");
        }
        if (list3.isEmpty() || !list4.isEmpty()) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PAY_EDIT_ERROR);
        }
        //成功返回
        return ResultDataDto.addOperationSuccess("成功");
    }

    /***
     * H5功能管理：方案启用
     * @param request
     * @param token
     * @return
     */
    @Override
    public ResultDataDto contentPlanOpen(RequestPlanOperation request, String token) {

        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        //1,先去公共服务类验证token
        String results = utilsService.checkAdmin(token);

        if (StringUtils.isBlank(results) || !StringOutputConstant.CODE_SUCCESS.equals(results)) {
            // 验证token出现问题，直接返回
            return ResultDataDto.addOperationFailure(results);
        }

        //确认安全，开始验证参数
        if (StringUtils.isBlank(request.getTradeType()) || StringUtils.isBlank(request.getLang()) || StringUtils.isBlank(request.getVersion()) ||
                StringUtils.isBlank(request.getPartnerCode()) || StringUtils.isBlank(request.getConfigType()) || StringUtils.isBlank(request.getConfigStatus()) ||
                StringUtils.isBlank(request.getPlanCode())) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_ERROR);
        }

        if (request.getConfigStatus().equals("1") || request.getConfigStatus().equals("3")) {

            Integer contCount = configMapper.queryConfig(request.getPartnerCode(), request.getConfigStatus());

            if (contCount > 0) {

                Integer count = configMapper.queryConfigCount(request.getPartnerCode(), request.getConfigType());

                if (count < 1) {

                    //已停用的方案启用有一步特殊的处理，其他方案的状态方式相同
                    if (request.getConfigStatus().equals("3")) {

                        //已停用的方案启用：（方案停用之后再启用需将对应的方案套餐置为“已下架”如果方案下面已经有套餐的话，同时需将方案状态置为“已启用”）

                        //那么第一步就应该先去新建的套餐计划服务列表中查询：是否具有当前这个企业，当前这个这个方案的套餐列表。
                        List<PartnerServicePlan> serverList = configMapper.queryServicePlanCount(request.getPartnerCode(), request.getConfigType());

                        if (null != serverList && !serverList.isEmpty()) {

                            //查询到条数>1,说明套餐服务列表中存在当前企业和方案的数据，那么直接将这些套餐的状态置为“已下架”；反之，如果没有就不作任何操作
                            for (PartnerServicePlan s : serverList) {

                                PartnerServicePlan plan = new PartnerServicePlan();
                                plan.setPartnerCode(s.getPartnerCode());
                                plan.setConfigType(s.getConfigType());
                                plan.setPlanCode(request.getPlanCode());
                                plan.setServicePlanStatus("3");
                                plan.setPutoffDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
                                configMapper.operationServicePlan(plan);

                            }

                        }
                    }

                    //已停用的方案启用==新建的方案启用：（都需要将方案状态置为“已启用”）
                    PartnerConfigContent config = new PartnerConfigContent();
                    config.setPlanCode(request.getPlanCode());
                    config.setPartnerCode(request.getPartnerCode());
                    config.setConfigType(request.getConfigType());
                    config.setConfigStatus("2");
                    Integer configCount = configMapper.operationContentPlan(config);

                    if (configCount > 0) {
                        //成功
                        return ResultDataDto.addOperationSuccess();
                    } else {
                        return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_OPEN_ERROR);

                    }

                } else {
                    return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_CONFIG_EXIST_ERROR);
                }
            } else {
                // 上报的参数有误
                return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_ERROR);
            }

        } else {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_OPERATE_ERROR);
        }


    }

    /***
     * H5功能管理：方案停用
     * @param request
     * @param token
     * @return
     */
    @Override
    public ResultDataDto contentPlanStop(RequestPlanOperation request, String token) {

        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        //1,先去公共服务类验证token
        String results = utilsService.checkAdmin(token);

        if (StringUtils.isBlank(results) || !StringOutputConstant.CODE_SUCCESS.equals(results)) {
            // 验证token出现问题，直接返回
            return ResultDataDto.addOperationFailure(results);
        }

        //确认安全，开始验证参数
        if (StringUtils.isBlank(request.getTradeType()) || StringUtils.isBlank(request.getLang()) || StringUtils.isBlank(request.getVersion()) ||
                StringUtils.isBlank(request.getPartnerCode()) || StringUtils.isBlank(request.getConfigType()) || StringUtils.isBlank(request.getConfigStatus())
                || StringUtils.isBlank(request.getPlanCode())) {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_PARAM_ERROR);
        }

        if (request.getConfigStatus().equals("1") || request.getConfigStatus().equals("2")) {

            Integer contCount = configMapper.queryConfig(request.getPartnerCode(), request.getConfigStatus());

            if (contCount > 0) {

                //已启用的方案停用有一步特殊的处理，未启用的方案不涉及套餐服务计划的状态的修改

                if (request.getConfigStatus().equals("2")) {

                    //已启用的方案停用：（方案启用之后再停用需将对应的方案套餐置为“已弃用”如果方案下面已经有套餐的话，同时需将方案状态置为“已停用”）

                    //那么第一步就应该先去新建的套餐计划服务列表中查询：是否具有当前这个企业，当前这个这个方案的套餐列表。
                    List<PartnerServicePlan> serverList = configMapper.queryServicePlanCount(request.getPartnerCode(), request.getConfigType());

                    if (null != serverList && !serverList.isEmpty()) {

                        //查询到条数>1,说明套餐服务列表中存在当前企业和方案的数据，那么直接将这些套餐的状态置为“已弃用”，状态值为0；反之，如果没有就不作任何操作

                        for (PartnerServicePlan s : serverList) {

                            PartnerServicePlan plan = new PartnerServicePlan();
                            plan.setPartnerCode(s.getPartnerCode());
                            plan.setConfigType(s.getConfigType());
                            plan.setPlanCode(request.getPlanCode());
                            plan.setServicePlanStatus("0");
                            configMapper.operationServicePlan(plan);

                        }

                    }
                }

                //已启用的方案停用==新建的方案停用：（都需要将方案状态置为“已停用”）
                PartnerConfigContent config = new PartnerConfigContent();
                config.setPlanCode(request.getPlanCode());
                config.setPartnerCode(request.getPartnerCode());
                config.setConfigType(request.getConfigType());
                config.setConfigStatus("3");
                Integer configCount = configMapper.operationContentPlan(config);

                if (configCount > 0) {
                    //成功
                    return ResultDataDto.addOperationSuccess();
                } else {
                    return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_STOP_ERROR);
                }
            } else {
                // 上报的参数有误
                return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_ORDER_ERROR);
            }

        } else {
            // 上报的参数有误
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_OPERATE_ERROR);
        }

    }
}
